﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration;


namespace Portal.Maping
{
    /// <summary>
    /// 实体映射配置类 Province
    /// </summary>
    public class ProvinceMap:EntityTypeConfiguration<Entities.Province>
    {
        //配置要求：
        //ProvinceID 配置为主键 不能为null

        public ProvinceMap()
        {
            //配置主键
            this.HasKey(p => p.ProvinceID);
          

            //配置属性
            this.Property(p => p.ProvinceName).IsRequired().HasColumnType("nvarchar").HasMaxLength(50);
            this.Property(p => p.ProvinceNo).IsRequired().HasColumnType("nvarchar").HasMaxLength(10);
            this.Property(p => p.CategoryID).IsRequired().HasColumnType("int");

            //配置表名、列名
            this.Property(p => p.CategoryID).HasColumnName("CategoryID");
            this.Property(p => p.ProvinceID).HasColumnName("ProvinceID");
            this.Property(p => p.ProvinceName).HasColumnName("ProvinceName");
            this.Property(p => p.ProvinceNo).HasColumnName("ProvinceNo");

            //配置表间关系
            this.HasRequired(p => p.Category).WithMany(p => p.Province).HasForeignKey(p => p.CategoryID);


        }
    }
}
